import { reqCategoryListData,reqBannerListData,reqFloorListData } from '@/api'

const homeStore = {
    namespaced:true,
    state:{
        categoryList:[],
        bannerList:[],
        floorList:[]
    },
    getters:{},
    actions:{
        //获取分类列表的actions
        async getCategoryListData({ commit }){
            console.log('发送请求获取categoryList数据啦');
            const result = await reqCategoryListData() //用await等待数据请求回来
            if(result.data.code === 200){
                commit('UPDATE_CATEGORY_LIST_DATA',result)
            }else{
                console.log('请求数据失败');
            }
        },
        //获取轮播图的数据
        async getBannerListData({commit}) {
            const result = await reqBannerListData() //用await等待数据请求回来
            if(result.data.code === 200) {
                commit('UPDATE_BANNER_LIST_DATA',result)
            }else{
                console.log('请求banner数据失败');
            }
        },
        //获取楼层数据
        async getFloorListData({commit}){
            const result = await reqFloorListData()
            if(result.data.code === 200){
                commit('UPDATE_FLOOR_LIST_DATA',result)
            }else{
                console.log('请求floor数据失败');
            }   
        }
    },
    mutations:{
        UPDATE_CATEGORY_LIST_DATA(state,payload){
            state.categoryList = payload.data.data
            console.log('state.categoryList',state.categoryList);
        },
        UPDATE_BANNER_LIST_DATA(state,payload){
            state.bannerList = payload.data.data
            console.log('state.bannerList',state.bannerList);
        },
        UPDATE_FLOOR_LIST_DATA(state,payload){
            state.floorList = payload.data.data
            console.log('state.floorList',state.floorList);
        }
    },
}

export default homeStore